package com.ease.model.typehandler;

import java.sql.SQLException;

import org.postgis.Geometry;
import org.postgis.PGgeometry;

import com.ease.model.util.PostgreSqlSpatialGeometryUtil;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;

/**
 * 
 * @author nathanleewei
 * 
 */
public class PgGeoPolygonTypeHandler extends GeometryTypeHandler {

	public PgGeoPolygonTypeHandler() {
		super();
	}

	private Object getResult(Object object) throws SQLException {
		if (null != object) {
			PGgeometry geometry = (PGgeometry) object;
			if (null != geometry && geometry.getGeoType() == Geometry.POLYGON) {
				return PostgreSqlSpatialGeometryUtil.toGeoPolygon(geometry);
			}
		}
		return null;

	}

	public Object valueOf(String s) {
		// TODO
		return null;
	}

	public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {

		// PreparedStatement ps = setter.getPreparedStatement();
		//
		// Connection conn = this.getOracleConnection(ps);
		// Assertion.notNull(conn, "OracleConnection not found");
		//
		// JGeometry geometry = PostgreSqlSpatialGeometryUtil.fromGeoPolygon((GeoPolygon) parameter);
		//
		// STRUCT struct = JGeometry.store(geometry, conn);
		//
		// setter.setObject(struct);
	}

	public Object getResult(ResultGetter getter) throws SQLException {

		return getResult(getter.getResultSet().getObject(getter.getColumnName()));
	}
}
